{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:No training configuration found in save file: the model was *not* compiled. Compile it manually.\n",
      "AD06883\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import cv2\n",
    "import tensorflow as tf\n",
    "import matplotlib.pyplot as plt\n",
    "from tensorflow.keras.applications import ResNet50,MobileNetV2,Xception,NASNetLarge,InceptionResNetV2\n",
    "\n",
    "os.environ['TF_CPP_MIN_LOG_LEVEL']='2'\n",
    "gpus = tf.config.experimental.list_physical_devices('GPU')\n",
    "tf.config.experimental.set_memory_growth(gpus[0], True)\n",
    "\n",
    "model = tf.keras.models.load_model('./h5model/model.h5')\n",
    "shoes_type = [\"AD06883\",\"AD18581\",\"AD36270\",\"AD41719-1\",\"AD41719-1H\",\"AD41743\",\"AD43671\"]\n",
    "\n",
    "def readimg(path):\n",
    "    \n",
    "    images = tf.io.read_file(path, 'r')\n",
    "    images = tf.image.decode_bmp(images, channels = 3)\n",
    "    images = tf.cast(images, dtype=tf.float32) / 255. -0.5\n",
    "    images = tf.image.resize(images,(600, 854))  \n",
    "    images = tf.expand_dims(images,axis = 0)\n",
    "    return images\n",
    "\n",
    "def test_one_image(jpg_path):\n",
    "    \n",
    "    x = readimg(jpg_path)\n",
    "    logits = model(x)\n",
    "    prob = tf.nn.softmax(logits, axis=1)\n",
    "    pred = tf.argmax(prob, axis=1)\n",
    "    pred = tf.cast(pred, dtype=tf.int32)\n",
    "    return shoes_type[int(pred)]\n",
    "\n",
    "print(test_one_image('F:/dataset/0_shoes/classification/test/AD06883/20191216182941751.bmp'))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
